<?php
declare(strict_types=1);
use Yaf\Exception\StartupError;
use Yaf\Exception\TypeError;
if (!extension_loaded("yaf")) die("YAF extension is not installed!");
if (!extension_loaded("yac")) die("YAC extension is not installed!");
if (!extension_loaded("redis")) exit("Redis extension is not installed!");
if (extension_loaded("xhprof")) {
    if (IS_XHPROF) {
        ini_set("xhprof.output_dir", __ROOT__ . "/xhprof/temp/");
        xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
        require "xhprof/xhprof_lib/utils/xhprof_lib.php";
        require "xhprof/xhprof_lib/utils/xhprof_runs.php";
    }
}
//获取当前相对地址
if (! defined('_PHP_FILE_')) {
    $_temp = explode('.php', $_SERVER['PHP_SELF']);
    define('_PHP_FILE_', rtrim(str_replace($_SERVER['HTTP_HOST'], '', $_temp[0] . '.php'), '/'));
} else {
    define('_PHP_FILE_', rtrim($_SERVER['SCRIPT_NAME'], '/'));
}
if (! defined('__PATH__')) {
    $_root = rtrim(dirname(_PHP_FILE_), '/');
    define('__PATH__', (($_root == '/' || $_root == '\\') ? '' : $_root));
}
try {
    $app = new Yaf\Application(__ROOT__ . "/conf/app.ini");
    define("APP_PATH",$app->getAppDirectory());
    if (!is_dir(PUBLIC_PATH)) mkdir(PUBLIC_PATH, 0665, true);
    if (!is_dir(RUNTIME_PATH)) mkdir(RUNTIME_PATH, 0665, true);
    $app->bootstrap()->run();
} catch (StartupError|TypeError $exception) {
    Log::$customFileName = LOG_PATH."/errors/";
    Log::error($exception->getMessage().$exception->getTraceAsString());
}


